
# def metric(fn):
#     start_time = time.time()
#     end_time = time.time()
#     print('耗时s'.format(end_time-start_time))
#     return fn

# 定义函数
import functools
# 定义一个装饰器
import time
def log(f):
    @functools.wraps(f)
    def write_log(*args,**kw):  # 写入日志，函数和关键字
        start_time = time.time()  # 运行函数开始时间
        value = f(*args,**kw)
        end_time = time.time()  # 运行函数结束时间
        print('耗时{:4f}s'.format(end_time-start_time))
        return value
    return write_log
@log   # 写成装饰器
def waste_time():
   ulist = []
   for i in range():
       ulist.append(i)
print(waste_time)

#  函数定义
import time
def metric(fn):
    def write_log(*args,**kw): # 写入日志，函数和关键字
        start_time = time.time()
        end_time = time.time()
        print('耗时{:4f}s'.format(end_time-start_time))
        return fn
    return write_log
@log
def waste_time():
    print(waste_time)
f1=log(waste_time)
f1()


